<template>
	<view class="wrap">
		<u-form :model="dataForm" ref="uForm">
			<u-form-item label-position="left" label="打卡类型:" prop="reportTypeName" label-width="20%">
				<text v-if="!dataForm.attendanceName" @click="typeShow = true;">请选择打卡类型</text>
				<text v-else @click="typeShow = true;">{{dataForm.attendanceName}}</text>
				<u-picker mode="selector" v-model="typeShow" :default-selector="[0]" :range="reportTypeOptions"
					range-key="label" @confirm="typeConfirm"></u-picker>
				<u-icon slot="right" name="arrow-right" @click="typeShow = true;"></u-icon>
			</u-form-item>
		</u-form>
		<u-button @click="submit" type="primary">立即打卡</u-button>
	</view>
	</view>
</template>

<script>
	import {
		submitAttendance
	} from '@/api/attendance/attendance.js'
	export default {
		data() {
			return {
				dataForm: {
					attendanceType: '',
					attendanceName: ''
				},
				typeShow: false,
				reportTypeOptions: [{
						label: '上班打卡',
						value: 0
					},
					{
						label: '下班打卡',
						value: 1
					}
				]
			}
		},
		methods: {
			typeConfirm(e) {
				this.dataForm.attendanceName = this.reportTypeOptions[e].label
				this.dataForm.attendanceType = this.reportTypeOptions[e].value
			},
			submit() {
				console.log(this.dataForm)
				submitAttendance(this.dataForm).then(res => {
					if (res.code == 0) {
						uni.showToast({
							title: '打卡成功！',
							icon: 'success'
						});
						uni.switchTab({
							url: '/pages/home/home'
						});
					} else {
						uni.showToast({
							title: res.data.msg,
							icon: 'error'
						});
					}
				})
			}
		}
	};
</script>

<style scoped lang="scss">
	.wrap {
		padding: 30rpx;
	}

	.agreement {
		display: flex;
		align-items: center;
		margin: 40rpx 0;

		.agreement-text {
			padding-left: 8rpx;
			color: $u-tips-color;
		}
	}
</style>